package com.xmy.cultivate.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.xmy.cultivate.entity.OrderTransferDetail;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author min
 * @since 2022-08-12
 */
public interface OrderTransferDetailMapper extends BaseMapper<OrderTransferDetail> {

    @Select("select a.order_id from order_transfer_detail as a LEFT JOIN order_detail as b on a.old_order_detail_id = b.id ${ew.customSqlSegment}")
    public List<Long> getStudentIdListForWhere(@Param(Constants.WRAPPER) Wrapper wrapper);

    @Select("select IFNULL(sum(out_price),0) as out_price from order_transfer_detail where order_id = ${orderId}")
    public BigDecimal getOutPrice(@Param("orderId") Long orderId);

    @Select("select IFNULL(sum(out_price),0) from order_detail where id in(select old_order_detail_id from order_transfer_detail where order_id = ${orderId})")
    public BigDecimal getOrderDetaillOutPrice(@Param("orderId") Long orderId);

    @Select("select old_order_id from order_transfer_detail where order_id =  ${orderId}  limit 1")
    public Long getOldOrderId(@Param("orderId") Long orderId);
}
